﻿using Lisp.Compiler;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Excel.Expressions.Tests
{


    /// <summary>
    ///Это класс теста для ProgramTest, в котором должны
    ///находиться все модульные тесты ProgramTest
    ///</summary>
    [TestClass()]
    public class Test10
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Получает или устанавливает контекст теста, в котором предоставляются
        ///сведения о текущем тестовом запуске и обеспечивается его функциональность.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Дополнительные атрибуты теста
        // 
        //При написании тестов можно использовать следующие дополнительные атрибуты:
        //
        //ClassInitialize используется для выполнения кода до запуска первого теста в классе
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //ClassCleanup используется для выполнения кода после завершения работы всех тестов в классе
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //TestInitialize используется для выполнения кода перед запуском каждого теста
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //TestCleanup используется для выполнения кода после завершения каждого теста
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_1()
        {
            Processor stack = new Processor(2);

            stack.Input = new double[] { 1, 2, 5 };
            stack.Output = new double[] { 0 };

            stack.Code = new[]
            {
                Processor.Push(stack),
                Processor.Push(stack),
                Processor.Add(stack), 
                Processor.Push(stack), 
                Processor.Add(stack),  
                Processor.Pop(stack)
            };

            stack.Initialize();
            stack.Process();

            double expected = 8;
            double actual = stack.Output[0];

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_2()
        {
            try
            {
                Processor stack = new Processor(1);

                stack.Input = new double[] { 1, 2, 5 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Pop(stack), 
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_3()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 5 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Pop(stack),
                    Processor.Pop(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_4()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 5 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Add(stack),
                    Processor.Push(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_5()
        {
            try
            {
                Processor stack = new Processor(-1);
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_6()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = null;
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize();
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_7()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_8()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_9()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 3 };
                stack.Output = null;

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_10()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 3 };
                stack.Output = new double[] { };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_11()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 3 };
                stack.Output = new double[] { 3, 4 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),  
                    Processor.Push(stack), 
                    Processor.Add(stack),  
                    Processor.Pop(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_12()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 3 };
                stack.Output = new double[] { 3, 4 };

                stack.Code = null;

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_13()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2, 3 };
                stack.Output = new double[] { };

                stack.Code = new Instruction<Processor>[]
                {
                };

                stack.Initialize();
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_14()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Pop(stack)
                };

                stack.Initialize();
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_15()
        {
            try
            {
                Processor stack = new Processor(4);

                stack.Input = new double[] { 1, 2 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack),
                    Processor.Push(stack),
                    Processor.Add(stack),
                    null,
                    Processor.Pop(stack)
                };

                stack.Initialize();
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }

        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_16()
        {
            try
            {
                Processor stack = new Processor(2);

                stack.Input = new double[] { 1, 2 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Push(stack)
                };

                stack.Initialize(); 
                stack.Process();
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }


        /// <summary>
        ///Тест для Eval
        ///</summary>
        [TestMethod()]
        public void Test10_17()
        {
            try
            {
                Processor stack = new Processor(2);

                stack.Input = new double[] { 1 };
                stack.Output = new double[] { 0 };

                stack.Code = new Instruction<Processor>[]
                {
                    Processor.Pop(stack)
                };
            }
            catch (ArgumentException)
            {
                return;
            }
            Assert.Fail();
        }
    }
}
